// app.js
App({
  player: {
    list: [],
    current_music: 0,
    mode: 0,            // 0 单曲    1 顺序   2 随机
    status: 0,          // 0 未播放  1 播放   2 暂停中  3 已结束
    playbackRate: 1,    // 倍速
    a_resource: '',
    i_resource: '',
    global_show: 0,     // 全局显示  0 不显示 1 显示
    playing: {
      id: '',
      name: '',
      cover: '',
      url: '',
      singer: {
        avatar: '',
        name: ''
      },
      currentTime: 0,
      duration: 0,
      timeArr: [],
      lrcArr: []
    }
  },
   audioDom: wx.getBackgroundAudioManager(),
  initAudio(){
    this.audioDom.title = '起风了';
    this.audioDom.epname = '555';
    this.audioDom.singer = 'mySkey';
    this.audioDom.coverImgUrl = 'http://img.22family.com/mySKey/favicon.ico';
    this.audioDom.paused = true;
    this.audioDom.stop = true;
  },
  onShow(){
    if(this.audioDom.paused){
      this.player.status = 2;
    }
  },
  onLaunch() {
    this.initAudio()


    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })

     // 获取手机系统信息
     wx.getSystemInfo({
      success: res => {
        // 手机系统状态栏高度
        wx.setStorageSync('statusBarHeight', res.statusBarHeight)
        const platform = res.platform
        const menu =  wx.getMenuButtonBoundingClientRect()
        // 导航栏高度
        platform === 'android' ?  wx.setStorageSync('navHeight', 48 + res.safeArea.top) : wx.setStorageSync('navHeight', 44 + res.safeArea.top)
        wx.setStorageSync('windowHeight', res.windowHeight)
        //menu为胶囊，判断是否能读到胶囊位置，读不到则用具体一般数值表示
        if (menu) {
          wx.setStorageSync('menu', menu)
          // 导航栏高度
          wx.setStorageSync('navBarHeight', menu.height+(menu.top-res.statusBarHeight) *2 )
          // 状态栏加导航栏
          wx.setStorageSync('navStatusBarHeight', res.statusBarHeight+ menu.height+(menu.top-res.statusBarHeight) *2 )
        }else{
          wx.setStorageSync('menu', null)
          // 导航栏高度
          wx.setStorageSync('navBarHeight', platform === 'android' ? 48 : 44)
           // 状态栏加导航栏
          wx.setStorageSync('navStatusBarHeight', res.statusBarHeight+ (platform === 'android' ? 48 : 44) )
        }
 
      }, fail(err) {
        console.log(err);
      }
    })
  },
  
  globalData: {
    userInfo: null
  }
})
